export function getShiftTime() {
  const h08m30 = new Date();
  h08m30.setHours(8, 30, 0, 0);
  const h20m30 = new Date();
  h20m30.setHours(20, 30, 0, 0);

  const now = new Date();

  if (now < h08m30) {
    h20m30.setDate(h20m30.getDate() - 1);
    return [h20m30, h08m30];
  } else if (now >= h20m30) {
    h08m30.setDate(h08m30.getDate() + 1);
    return [h20m30, h08m30];
  } else {
    return [h08m30, h20m30];
  }
}

const zeroFill = (field) => (field < 10 ? "0" + field : field);

export function time2string(time) {
  const datetime = new Date(time);
  const year = datetime.getFullYear();
  const month = datetime.getMonth();
  const day = datetime.getDate();
  const hour = datetime.getHours();
  const minute = datetime.getMinutes();
  const second = datetime.getSeconds();
  return (
    `${year}-${zeroFill(month + 1)}-${zeroFill(day)} ` +
    `${zeroFill(hour)}:${zeroFill(minute)}:${zeroFill(second)}`
  );
}
